//  
//  Sprawdzacz
//  
//  Author:
//       Grzegorz Żur <grzegorz.zur@gmail.com>
// 
//  Copyright (c) 2010-2011 Grzegorz Żur
// 
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
// 
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

using System;
using System.Text.RegularExpressions;

namespace Sprawdzacz
{

	public class IBANPL : IBAN
	{

		public const string NAME = "Numer konta IBAN";

		private static readonly Regex PATTERN = new Regex ("^[0-9]{26}$");

		public IBANPL () : base(NAME)
		{
		}

		public override Validation Validate (string number)
		{
			number = Normalize (number);
			if (!PATTERN.IsMatch (number))
				return new Validation (false, Name, number, null);
			
			Validation validation = base.Validate ("PL" + number);
			if (!validation.Correct)
				return new Validation (false, Name, number, null);
			else {
				string message = string.Format ("{0} {1} {2} {3} {4} {5} {6}", number.Substring (0, 2), number.Substring (2, 4), number.Substring (6, 4), number.Substring (10, 4), number.Substring (14, 4), number.Substring (18, 4), number.Substring (22, 4));
				return new Validation (true, Name, number, message);
			}
		}
		
	}
	
}
